package com.mx.selenium;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by miaoxie on 2017/3/29.
 */
public class ZhiLian {
    WebDriver webdriver;
    List<WebElement> bt;
    @Test
    public void init(){


        String driverLoc = "util/chromedriver.exe";
        String driver = "webdriver.chrome.driver";

        System.setProperty(driver, driverLoc);
        webdriver = new ChromeDriver();
        for(int i = 0;i<10;i++){
            getNewsList(i+1);
            for(WebElement w : bt){
                List<Object> list = getNews(w);
            }
        }



    }
    private void getNewsList(int pageNo){

        webdriver.get("http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%E4%B8%8A%E6%B5%B7&kw=java&p="+pageNo);
        bt = webdriver.findElements(By.xpath("//*[@id=\"newlist_list_content_table\"]/table[2]/tbody"));


    }
    //*[@id="newlist_list_content_table"]/table[2]
    //*[@id="newlist_list_content_table"]/table[2]/tbody/tr[2]
    //*[@id="newlist_list_content_table"]/table[2]/tbody/tr[1]/td[1]/div/a
    //#newlist_list_content_table > table:nth-child(2) > tbody > tr:nth-child(1) > td.zwmc > div
    private List<Object> getNews(WebElement webElement){
        List<WebElement> webe = webElement.findElements(By.xpath("tr/td[1]/div/a"));//获取职位名称
        String job = webe.get(0).getAttribute("innerText");
        String jobHref = webe.get(0).getAttribute("href");
        webe = webElement.findElements(By.xpath("tr/td[2]/span"));//获取反馈率
        String fk_lv = webe.get(0).getAttribute("innerHTML");
        webe = webElement.findElements(By.xpath("tr/td[3]/a"));//获取公司信息
        String gsmc =webe.get(0).getAttribute("innerText");
        String gsmcHref = webe.get(0).getAttribute("href");
        webe = webElement.findElements(By.xpath("tr/td[4]"));//获取薪资信息
        String zwyx = webe.get(0).getAttribute("innerText");
        webe = webElement.findElements(By.xpath("tr/td[5]"));//获取工作地点
        String gzdd =webe.get(0).getAttribute("innerText");
        webe = webElement.findElements(By.xpath("tr/td[6]/span"));//获取发布时间
        String gxsj =webe.get(0).getAttribute("innerText");
        return null;
    }
    @Test
    public void dg(){
        f(10);
    }
    private static int f(int n){
        if(n==0 || n==1)
            return n;
        else
            return f(n-1)+f(n-2);
    }

}
